package loading
{
   import flash.display.MovieClip;
   import flash.net.URLRequest;
   
   import jp.nium.display.getInstanceById;
   import jp.progression.commands.display.AddChild;
   import jp.progression.commands.display.RemoveChild;
   import jp.progression.commands.net.LoadScene;
   import jp.progression.scenes.SceneLoader;
   
   /**
    * @author cjboy1984@gmail.com
    */
   public class MySceneLoader extends SceneLoader
   {
      private var fileName:String;
      
      private function get mcLoading():MovieClip { return MovieClip(getInstanceById('main scene loading')); }
      
      public function MySceneLoader(swf:String, name:String = null, initObject:Object = null)
      {
         super(name, initObject);
         
         fileName = swf;
      }
      
      // --------------------- LINE ---------------------
      
      // ################### protected ##################
      
      override protected function atScenePreLoad():void
      {
         var loadScene:LoadScene = new LoadScene(new URLRequest(fileName), this, null);
         loadScene.onProgress = function()
         {
            // only set propority of "progress"
            if (mcLoading)
            {
               mcLoading.perc = int(100 * loadScene.bytesLoaded / loadScene.bytesTotal).toString() + ' %';
            }
         };
         
         // add loading
         if (mcLoading)
         {
            addCommand(
               new AddChild(container, mcLoading)
            );
         }
         
         // load
         addCommand(
            loadScene
         );
         
         // remove loading
         if (mcLoading)
         {
            addCommand(
               new RemoveChild(container, mcLoading)
            );
         }
      }
      
      override protected function atScenePostUnload():void
      {
         //unload();
      }
      
      // #################### private ###################
      
   }
   
}
